package com.itheima.service.Impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.SortingDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Sorting;
import com.itheima.service.SortingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 吴
 * @version V1.0
 * @Description
 * @Package com.itheima.service.Impl
 * @date 2021/12/8 15:05
 */
@Service(interfaceClass = SortingService.class)
@Transactional
public class SortingServiceImpl implements SortingService {

    @Autowired
    private SortingDao sortingDao;
    /**
     * 添加分院
     * @param sorting
     */
    @Override
    public void saveSorting(Sorting sorting) {
        sortingDao.insert(sorting);
    }

    /**
     * 根据条件查询
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult selectByCondition(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<Sorting> sortings = sortingDao.selectByCondition(queryPageBean.getQueryString());
        PageInfo<Sorting> pageInfo = new PageInfo<>(sortings);
        return new PageResult(pageInfo.getTotal(),pageInfo.getList());
    }

    /**
     * 根据Id 查询分院信息
     * @param id
     * @return
     */
    @Override
    public Sorting selectById(Integer id) {
        return sortingDao.selectById(id);
    }

    /**
     * 修改
     * @param sorting
     */
    @Override
    public void update(Sorting sorting) {
        sortingDao.update(sorting);
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(Integer id) {
        sortingDao.delete(id);
    }

    /**
     * 查询全部的分院信息
     * @return
     */
    @Override
    public List<Sorting> findSortingAll() {
        return sortingDao.findSortingAll();
    }
}
